package com.wonders.framework.auto.builder.code.convert.instance;

import com.wonders.framework.auto.builder.code.convert.BaseTagConvert;
import com.wonders.framework.auto.builder.code.entity.vo.BuildColumn;
import com.wonders.framework.auto.builder.code.entity.vo.BuildTable;

/**
 * 列表页查询标签转换器
 * 
 * @author WuBin
 * 
 */
public class ListQueryConvert extends BaseTagConvert {

	@Override
	public String convert(String str, String tag, BuildTable buildTable) {
		String prefix = super.getPrefix(str, tag);
		str = "";
		for (int i = 0; i < buildTable.getColumns().size(); i++) {
			BuildColumn buildColumn = buildTable.getColumns().get(i);
			if (i % 3 == 0) {
				str += prefix + "<tr height=\"34px\">";
				str += "\n";
			}
			str += prefix + "       <td align=\"right\"><span>"
					+ buildColumn.getPropertyMean() + "：</span></td>";
			str += "\n";
			str += prefix + "       <td><input name=\""
					+ buildColumn.getPropertyName() + "\"";
			if ("Date".equals(buildColumn.getTypeName())) {
				str += " class=\"mini-datepicker\" dateFormat=\"yyyy-MM-dd\"";
			} else {
				str += " class=\"mini-textbox\"";
			}
			if ("Long".equals(buildColumn.getTypeName())
					|| "Integer".equals(buildColumn.getTypeName())) {
				str += " vtype=\"int;maxLength:" + buildColumn.getMaxLength()
						+ ";\"";
			} else if ("String".equals(buildColumn.getTypeName())) {
				str += " vtype=\"maxLength:"
						+ Integer.parseInt(buildColumn.getMaxLength()) + ";\"";
			}
			str += "/></td>";
			str += "\n";
			if (i % 3 == 2) {
				str += prefix + "</tr>";
				str += "\n";
			}
			if (i + 1 == buildTable.getColumns().size()) {
				int lack = 2 - i % 3;
				while (lack > 0) {
					str += prefix + "       <td align=\"right\"></td>";
					str += "\n";
					str += prefix + "       <td></td>";
					str += "\n";
					lack--;
				}
				str += prefix + "</tr>";
			}
		}
		return str;
	}

}
